package com.example.blockingqueue.controller;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class Order implements Delayed {
    private final String orderNo;
    private final long time;

    public Order(String orderNo, long time) {
        this.orderNo = orderNo;
        this.time = time;
        System.out.println("订单号：" + orderNo + "已经被创建");
    }

    @Override/*getDelay--获取现在还有多久才会被消费*/
    public long getDelay(TimeUnit unit) {
        return time - System.currentTimeMillis();
    }

    @Override/*决定队列中的顺序，谁在前 谁在后*/
    public int compareTo(Delayed o) {
        Order order = (Order) o;
        return Long.compare(this.time, order.time);
    }

    public void run() {
        System.out.println("订单号：" + orderNo + "已经被消费");
    }
}